package com.bsoft.utils;

import cn.hutool.http.webservice.SoapClient;
import com.bsoft.Exception.CommonException;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringEscapeUtils;
import org.springframework.beans.factory.annotation.Value;

import java.util.Map;

@Slf4j
public class WebserviceClient {



    public static String webServiceInvoker(String parmStr, String meth,String url)  throws Exception{
        String response = "";
        try {
            SoapClient client = SoapClient.create(url)
                    // 设置要请求的方法，此接口方法前缀为web，传入对应的命名空间
                    .setMethod("ser:"+meth, "http://service.bsoft.com/")
                    // 设置参数，此处自动添加方法的前缀：web
                    .setParam("request",parmStr , false)
                    .setConnectionTimeout(60000)
                    .setReadTimeout(60000);
            response = client.send(true);
            response = StringEscapeUtils.unescapeXml(response);

            String[] splitArr = response.split(" <return>");
            response = splitArr[1];
            String[] splitArr1 = response.split("</return>");
            response = splitArr1[0];

        } catch (Exception e) {
            throw new CommonException("调用["+url+"]服务异常,"+e.getMessage());
        }
        return response;
    }
}
